/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-03-15 10:39:50
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2024-03-19 09:05:00
 * @FilePath: \dm\云课堂\js\details.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
$(function () {
    /*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-03-15 10:39:50
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2024-03-18 20:15:40
 * @FilePath: \dm\云课堂\js\details.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
$(function () {
    // 判断是否登录
    if (localStorage.getItem('userInfo')) {
        $('#userIn > .tips, .glyphicon').remove();
        var userInfo = JSON.parse(localStorage.getItem('userInfo'));
                    $('.goin').append(`
                    <div class="userIn">
                        <div class="userImg">
                            <img src="./images/userAvatar_1431_微信图片_20231103095832-1754844961339080704.jpg" alt="">
                        </div>
                        <div class="userName">
                            ${userInfo.nickname}
                        </div>
                        <div class="userVip">
                            <img data-v-5c89a100="" src="" alt="">
                            青铜会员
                        </div>
                    </div>
                    `);
                    // 登录退出下拉菜单
                    $('.goin').hover(
                        function() {
                            $('.topDown').stop().slideToggle();
                        },
                        function() {
                            $('.topDown').stop().slideToggle();
                        }
                    );
    }
    // 请求下拉列表数据
    $.ajax({
        url: `https://wkt.myhope365.com//weChat/applet/subject/list`,
        type: 'post',
        headers: {
            'Content-type': 'application/json',
        }, //请求头
        data: JSON.stringify({
            "enable": 1
        }),
        success(res) {
            console.log(res);
            if (res.code == 0) {
                res.rows.forEach(item => 
                    $('.pull-down').append(`<li><a href="#">${item.title}</a></li>`)
                )
            }
        },
        error: function (err) {
            console.log(err) //返回的数据
        }, //失败后
    })
    // 下拉列表
    // 当鼠标移入 .pullDown 元素时，显示下拉列表  
    $('.none').hover(
        function() {
            $('.pull-down').stop().slideToggle();
        },
        function() {
            $('.pull-down').stop().slideToggle();
        }
    )
    // 请求图片
    var id = window.location.href.split('?')[1].split('%')[0];
    var types = window.location.href.split('0')[3];
    // console.log(window.location.href.split('0')[3]);
    console.log(id);
    if (id == 103) {
        $.ajax({
            url: `https://wkt.myhope365.com//pc/course/detail/${id}`,
            type: 'get',
            success(res) {
                console.log(res);
                if (res.code == 0) {
                    if (types == 'discount') {
                        $('.content').append(`<img src="${res.data.coverFileUrl}">`),
                        $('.contentText').append(`
                                <h3>${res.data.courseTitle}</h3>
                                <p class="study">
                                    累计${res.data.learningNum}人学习
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                </p>
                                <p class="expense">${res.data.isFree == 1 ? '免费' : ''}<b style="color: red;">${res.data.isFree == 0 && res.data.isDiscount == 1 ? '￥' + res.data.discountPrice : ''}</b><del>${res.data.isFree == 0 && res.data.isDiscount == 1 ? '￥' + res.data.coursePrice : ''}<del></p>
                                <div data-v-7d9d9d80="" class="ant-tag ant-tag-orange">限时钜惠</div>
                                <button style="margin-top: 10px;">立即观看</button><button style="background-color: #FFE9E9; color: red; margin-top: 10px;">加入购物车</button>
                        `)
                    } else {
                        $('.content').append(`<img src="${res.data.coverFileUrl}">`),
                        $('.contentText').append(`
                                <h3>${res.data.courseTitle}</h3>
                                <p class="study">
                                    累计${res.data.learningNum}人学习
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                </p>
                                <p class="expense">${res.data.isFree == 1 ? '免费' : ''}<b style="color: red;">${res.data.isFree == 0 && res.data.isDiscount == 1 ? '￥' + res.data.discountPrice : ''}</b><del>${res.data.isFree == 0 && res.data.isDiscount == 1 ? '￥' + res.data.coursePrice : ''}<del></p>
                                <button>立即观看</button><button style="background-color: #FFE9E9; color: red;">加入购物车</button>
                        `)
                    }
                    $('.sec_1').append(`${res.data.courseDetail}`),
                    $('.pd').click(function () {
                                $(this).addClass('liStyle').siblings().removeClass('liStyle');
                                if ($(this).index() == 0) {
                                    // $('.sec_1').append(`${item.courseDetail}`)
                                    $('#sec_3').removeClass('sec_3');
                                    $('.catalogue').removeClass('sec_2');
                                } else if ($(this).index() == 1) {
                                    // $('.sec_2').append(`${item.courseDetail}`).removeClass('sec_3');
                                    $('#sec_3').removeClass('sec_3');
                                    $('.catalogue').addClass('sec_2');
                                } else {
                                    // $('.sec_3').append(`${item.courseDetail}`).addClass('sec_3');
                                    $('#sec_3').addClass('sec_3');
                                    $('.catalogue').removeClass('sec_2');
                                }
                    }),
                    res.data.sections.forEach((item, index)=> {
                        if (index == 0) {
                            index = 1;
                            console.log('1');
                        } else if (index == 10) {
                            index = 10;
                        }
                        if (item.sectionId != 2234) {
                            $('#sec_2').append(`
                                <div>
                                    <h3>${index}. ${item.sectionName}</h3>
                                    <div data-v-3a7480b1="" class="ant-tag ant-tag-has-color"><i data-v-3a7480b1="" aria-label="icon: cloud-download" class="anticon anticon-cloud-download"><svg data-v-3a7480b1="" viewBox="64 64 896 896" data-icon="cloud-download" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M624 706.3h-74.1V464c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v242.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.7a8 8 0 0 0 12.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9z"></path><path d="M811.4 366.7C765.6 245.9 648.9 160 512.2 160S258.8 245.8 213 366.6C127.3 389.1 64 467.2 64 560c0 110.5 89.5 200 199.9 200H304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8h-40.1c-33.7 0-65.4-13.4-89-37.7-23.5-24.2-36-56.8-34.9-90.6.9-26.4 9.9-51.2 26.2-72.1 16.7-21.3 40.1-36.8 66.1-43.7l37.9-9.9 13.9-36.6c8.6-22.8 20.6-44.1 35.7-63.4a245.6 245.6 0 0 1 52.4-49.9c41.1-28.9 89.5-44.2 140-44.2s98.9 15.3 140 44.2c19.9 14 37.5 30.8 52.4 49.9 15.1 19.3 27.1 40.7 35.7 63.4l13.8 36.5 37.8 10C846.1 454.5 884 503.8 884 560c0 33.1-12.9 64.3-36.3 87.7a123.07 123.07 0 0 1-87.6 36.3H720c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h40.1C870.5 760 960 670.5 960 560c0-92.7-63.1-170.7-148.6-193.3z"></path></svg></i>下载</div>
                                </div>
                            `)
                        }
                        [... new Set(item.subSections)].forEach((value, key) => {
                            if (item.sectionId != 2234) {
                                $('#sec_2').append(`
                                    <li><span>${index}-${key + 1} ${value.sectionName}</span><div data-v-3a7480b1="" class="section-action"><span data-v-3a7480b1=""><span data-v-3a7480b1="" class="play-icon"><i data-v-3a7480b1="" aria-label="icon: play-circle" class="anticon anticon-play-circle"><svg data-v-3a7480b1="" viewBox="64 64 896 896" data-icon="play-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M719.4 499.1l-296.1-215A15.9 15.9 0 0 0 398 297v430c0 13.1 14.8 20.5 25.3 12.9l296.1-215a15.9 15.9 0 0 0 0-25.8zm-257.6 134V390.9L628.5 512 461.8 633.1z"></path></svg></i></span><span data-v-3a7480b1="" class="play-text"> 观看 </span></span></div></li>
                                `)
                            }
                        })
                    })
                }
            },
            error: function (err) {
                console.log(err) //返回的数据
            }, //失败后
        })
    }
    if (id != 103) {
        $.ajax({
            url: `https://wkt.myhope365.com//pc/course/detail/${id}`,
            type: 'get',
            success(res) {
                console.log(res);
                if (res.code == 0) {
                    if (types == 'discount') {
                        $('.content').append(`<img src="${res.data.coverFileUrl}">`),
                        $('.contentText').append(`
                                <h3>${res.data.courseTitle}</h3>
                                <p class="study">
                                    累计${res.data.learningNum}人学习
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                </p>
                                <p class="expense">${res.data.isFree == 1 ? '免费' : ''}<b style="color: red;">${res.data.isFree == 0 && res.data.isDiscount == 1 ? '￥' + res.data.discountPrice : ''}</b><del>${res.data.isFree == 0 && res.data.isDiscount == 1 ? '￥' + res.data.coursePrice : ''}<del></p>
                                <div data-v-7d9d9d80="" class="ant-tag ant-tag-orange">限时钜惠</div>
                                <button style="margin-top: 10px;">立即观看</button><button style="background-color: #FFE9E9; color: red; margin-top: 10px;">加入购物车</button>
                        `)
                    } else {
                        $('.content').append(`<img src="${res.data.coverFileUrl}">`),
                        $('.contentText').append(`
                                <h3>${res.data.courseTitle}</h3>
                                <p class="study">
                                    累计${res.data.learningNum}人学习
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                    <img src="./images/213收藏.png" alt="">
                                </p>
                                <p class="expense">${res.data.isFree == 1 ? '免费' : ''}<b style="color: red;">${res.data.isFree == 0 && res.data.isDiscount == 1 ? '￥' + res.data.discountPrice : ''}</b><del>${res.data.isFree == 0 && res.data.isDiscount == 1 ? '￥' + res.data.coursePrice : ''}<del></p>
                                <button>立即观看</button><button style="background-color: #FFE9E9; color: red;">加入购物车</button>
                        `)
                    }
                    $('.sec_1').append(`${res.data.courseDetail}`),
                    $('.pd').click(function () {
                                $(this).addClass('liStyle').siblings().removeClass('liStyle');
                                if ($(this).index() == 0) {
                                    // $('.sec_1').append(`${item.courseDetail}`)
                                    $('#sec_3').removeClass('sec_3');
                                    $('.catalogue').removeClass('sec_2');
                                } else if ($(this).index() == 1) {
                                    // $('.sec_2').append(`${item.courseDetail}`).removeClass('sec_3');
                                    $('#sec_3').removeClass('sec_3');
                                    $('.catalogue').addClass('sec_2');
                                } else {
                                    // $('.sec_3').append(`${item.courseDetail}`).addClass('sec_3');
                                    $('#sec_3').addClass('sec_3');
                                    $('.catalogue').removeClass('sec_2');
                                }
                    }),
                    res.data.sections.forEach((item, index)=> {
                        index++;
                        if (item.sectionId != 2234) {
                            $('#sec_2').append(`
                                <div>
                                    <h3>${index}. ${item.sectionName}</h3>
                                    <div data-v-3a7480b1="" class="ant-tag ant-tag-has-color"><i data-v-3a7480b1="" aria-label="icon: cloud-download" class="anticon anticon-cloud-download"><svg data-v-3a7480b1="" viewBox="64 64 896 896" data-icon="cloud-download" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M624 706.3h-74.1V464c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v242.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.7a8 8 0 0 0 12.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9z"></path><path d="M811.4 366.7C765.6 245.9 648.9 160 512.2 160S258.8 245.8 213 366.6C127.3 389.1 64 467.2 64 560c0 110.5 89.5 200 199.9 200H304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8h-40.1c-33.7 0-65.4-13.4-89-37.7-23.5-24.2-36-56.8-34.9-90.6.9-26.4 9.9-51.2 26.2-72.1 16.7-21.3 40.1-36.8 66.1-43.7l37.9-9.9 13.9-36.6c8.6-22.8 20.6-44.1 35.7-63.4a245.6 245.6 0 0 1 52.4-49.9c41.1-28.9 89.5-44.2 140-44.2s98.9 15.3 140 44.2c19.9 14 37.5 30.8 52.4 49.9 15.1 19.3 27.1 40.7 35.7 63.4l13.8 36.5 37.8 10C846.1 454.5 884 503.8 884 560c0 33.1-12.9 64.3-36.3 87.7a123.07 123.07 0 0 1-87.6 36.3H720c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h40.1C870.5 760 960 670.5 960 560c0-92.7-63.1-170.7-148.6-193.3z"></path></svg></i>下载</div>
                                </div>
                            `)
                        }
                        [... new Set(item.subSections)].forEach((value, key) => {
                            if (item.sectionId != 2234) {
                                $('#sec_2').append(`
                                    <li><span>${index}-${key + 1} ${value.sectionName}</span><div data-v-3a7480b1="" class="section-action"><span data-v-3a7480b1=""><span data-v-3a7480b1="" class="play-icon"><i data-v-3a7480b1="" aria-label="icon: play-circle" class="anticon anticon-play-circle"><svg data-v-3a7480b1="" viewBox="64 64 896 896" data-icon="play-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M719.4 499.1l-296.1-215A15.9 15.9 0 0 0 398 297v430c0 13.1 14.8 20.5 25.3 12.9l296.1-215a15.9 15.9 0 0 0 0-25.8zm-257.6 134V390.9L628.5 512 461.8 633.1z"></path></svg></i></span><span data-v-3a7480b1="" class="play-text"> 观看 </span></span></div></li>
                                `)
                            }
                        })
                    })
                }
            },
            error: function (err) {
                console.log(err) //返回的数据
            }, //失败后
        })
    }
    // 课程描述\目录\评论判断
    $('.pd').click(function () {
        $('.sec').animate({'left':' -1140' * $(this).index() +'px'}, 100);
    })
    $(this).addClass('current').siblings('input').removeClass('current');
    $('.slides').animate({'left': -500 * $(this).index() +'px'}, 2000);
    // 登录与注册
    $('.user').click(function() {
        $(this).addClass('color_text').siblings('.pow').removeClass('color_text');
        $('#form-group').remove();
        $('.module_body').append(`
            <form class="form-group" id="form-group" action="">
                <div class="form-group input_user">
                    <img src="./images/用户名.png" alt="">
                    <input class="form-control" type="text" placeholder="请输入账户名">
                </div>
                <div class="form-group input_pow">
                    <img src="./images/密码.png" alt="">
                    <input class="form-control" type="password" placeholder="请输入密码">
                </div>
                <div class="text-right">
                    <button class="form-control btnIn" type="submit" style="color: #fff; background-color: #00CF8C; margin-top: 25px; margin-bottom: 20px;">登录</button>
                </div>
                <a href="" class="register href_a">立刻注册！</a>
                <a href="" class="forgot href_a">忘记密码？</a>
            </form>
        `);
    })
    $('.pow').click(function() {
        $(this).addClass('color_text').siblings('.user').removeClass('color_text');
        $('#form-group').remove();
        $('.module_body').append(`
            <form class="form-group" id="form-group" action="">
                <div class="form-group input_user">
                    <img src="./images/用户名.png" alt="">
                    <input class="form-control" type="text" placeholder="请输入手机号">
                </div>
                <div class="form-group input_pow verification">
                    <img src="./images/密码.png" alt="">
                    <input class="form-control" type="password" placeholder="请输入验证码" style="width: 158px;">
                    <button>获取验证码</button>
                </div>
                <div class="text-right">
                    <button class="form-control btnIn_1" type="submit" style="color: #fff; background-color: #00CF8C; margin-top: 0px; margin-bottom: 20px;">登录</button>
                </div>
                <a href="" class="register href_a">立刻注册！</a>
                <a href="" class="forgot href_a">忘记密码？</a>       
            </form> 
        `)
    })
    // 单击登录
    $('.btnIn').click(function () {
        var user = $('#user').val();
        var pow =  $('#pow').val();
        $.ajax({
            url: `https://wkt.myhope365.com/pcUser/login`,
            type: 'POST',
            data: {
                username: user,
                password: pow,
                rememberMe: true,
            },
            success(res) {
                console.log(res);
                if (res.code == 500) {
                    alert('用户不存在/密码错误');
                }
                if (res.code == 0) {
                    alert('成功登录');
                    $('#register').modal('hide');
                    $('#userIn > .tips, .glyphicon').remove();
                    $('.goin').append(`
                    <div class="userIn">
                        <div class="userImg">
                            <img src="./images/userAvatar_1431_微信图片_20231103095832-1754844961339080704.jpg" alt="">
                        </div>
                        <div class="userName">
                            ${res.userInfo.nickname}
                        </div>
                        <div class="userVip">
                            <img data-v-5c89a100="" src="" alt="">
                            青铜会员
                        </div>
                    </div>
                    `);
                }
                // 本地存储
                localStorage.setItem('userInfo', JSON.stringify(res.userInfo));
                window.location.reload();
            },
            error: function (err) {
                console.log(err) //返回的数据
            }, //失败后
        })
    })
    $('.out').click(function () {
        localStorage.removeItem('userInfo');
        window.location.reload();
    })
})

})
